package cn.gson.school.controller.jiuye;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import cn.gson.school.dao.ImagesDao;
import cn.gson.school.dao.jiuye.InterviewRecordEntityDao;
import cn.gson.school.entity.jiaoxue.StudentEntity;
import cn.gson.school.entity.jiuye.InterviewMaterialsEntity;
import cn.gson.school.entity.jiuye.InterviewRecordEntity;
import cn.gson.school.entity.jiuye.MultimediaEntity;
import cn.gson.school.entity.jiuye.RetestEntity;
import cn.gson.school.entity.xitong.ImageEntity;
import cn.gson.school.mappers.jiuye.FileEntityMapper;
import cn.gson.school.mappers.jiuye.InterviewMaterialsEntityMapper;
import cn.gson.school.mappers.jiuye.InterviewRecordEntityMapper;
import cn.gson.school.mappers.jiuye.MultimediaEntityMapper;
import cn.gson.school.mappers.jiuye.OfferEntityMapper;
import cn.gson.school.mappers.jiuye.RetestEntityMapper;

/**
 * 记录详情
 * 
 * @author 华少
 *
 */
@Controller
public class QianTaiJiLuXiangQing {
	@Autowired
	private InterviewRecordEntityDao interviewRecordEntityDao;
	@Autowired
	private InterviewRecordEntityMapper interviewRecordEntityMapper;
	@Autowired
	private InterviewMaterialsEntityMapper interviewMaterialsEntityMapper;
	@Autowired
	private MultimediaEntityMapper multimediaEntityMapperv;
	@Autowired
	private RetestEntityMapper retestEntityMapper;
	@Autowired
	private OfferEntityMapper offerEntityMapper;
	@Autowired
	private FileEntityMapper fileEntityMapper;
	@Autowired
	private ImagesDao imagesDao;
	

	@GetMapping({ "chaxunjiluxiangqing" })
	public String select1(Model model, HttpServletRequest request,HttpSession session) {
		try {
			String id = request.getParameter("id");
			session.setAttribute("interviewId",id);
			InterviewRecordEntity u = interviewRecordEntityDao.findOne(Long.valueOf(id));
			StudentEntity stu=	(StudentEntity) session.getAttribute("userinfo");
			if(u.getStudentinfoId().getStuId()==stu.getStuId()) {
				model.addAttribute("xxxx",1);
			}else {
				model.addAttribute("xxxx",2);
			}
			if (u != null){
				// 如果是编辑，则把原有用户信息传回表单页面
				StudentEntity e = u.getStudentinfoId();
				Long Interviewid = u.getInterviewId();
				// 查询所有的资料信息
				List<InterviewMaterialsEntity> materials = interviewMaterialsEntityMapper.chaxunziliao(Interviewid);
				Map<String, Object> multimedia = multimediaEntityMapperv.chaxunduomeiti(Interviewid);
				ImageEntity yin = null;
				if(multimedia!=null){
					yin=imagesDao.findOne((Long) multimedia.get("touxiang"));
					System.out.println(yin);
					model.addAttribute("yinpath","upload/"+yin.getImagePath());
					model.addAttribute("yin", yin);
				}
				
				// 查询复试
				List<RetestEntity> retest = retestEntityMapper.chaxunfushi(Interviewid);
				Map<String, Object> offer = offerEntityMapper.chaxunoffer(Interviewid);
				ImageEntity img = null;
				if (offer != null) {
					Long offerid = (Long) offer.get("offer_id");
					Map<String, Object> file = fileEntityMapper.chaxunguidang(offerid);
					model.addAttribute("file", file);
					System.out.println("查询file：" + file);
					Long imageid = (Long) offer.get("touxiang");
					img = imagesDao.findOne(imageid);
					System.out.println("查询img：" + img);					
					model.addAttribute("imgpath","upload/"+img.getImagePath());
					model.addAttribute("img", img);
				}
				System.out.println("面试资料："+materials);
				System.out.println("面试信息："+u);
				System.out.println("面试offer："+offer);
				System.out.println("面试retest"+retest);

				model.addAttribute("xinxi", u);
				model.addAttribute("xueshen", e);
				model.addAttribute("materials",materials);
				model.addAttribute("retest", retest);
				model.addAttribute("offer", offer);
			}
		} catch (Exception e) {
			System.out.println(e);
		}
		return "qt-jy-jinglixiangqing";
	}
}
